Basic
Linux
/** Node.js must be Installed */
npm install -g @angular/cli
npm install -g @angular/[email protected]
Windows
/** Node.js must be Installed */
npm install -g @angular/cli@17
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
Init
ng new appName /** Init project */
ng generate component componentName
Run
ng serve --open
// or
ng add @angular/pwa
ng build
ng serve --open
// oben ist das install icon
Code
<button (click)="func()"> </button>
<p *ngIf="count <= 1> Text </p>
<input [value]="firstName">
<button (click)="readRainbow($event)">
<div title="Hello {{ponyName}}">
// Binds a property to an interpolated string,
// for example, "Hello Seabiscuit". Equivalent to:
<div [title]="'Hello ' + ponyName">
<p> {{ varName }} </p>
// Component.ts:
// imports: [TestoloComponent, CommonModule], if you add a componnent
export class Testolo2Component implements OnInit {
ngOnInit() {}
}
Angular + SpringBoot
// WebConfig.java
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("http://localhost:4200")
.allowedMethods("GET", "POST", "PUT", "DELETE", "HEAD")
.allowCredentials(true);
}
}
// service.ts
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class UserService {
constructor(private http: HttpClient) {
}
public getUsers(): Observable<any> {
return this.http.get("http://localhost:8080/api/users");
}
}